<?php
declare(strict_types=1);

namespace app\validate;

class AdminValidate extends BaseValidate
{
    protected $rule = [
        'username'  => 'require|length:4,20',
        'password'  => 'require|length:6,20',
        'role_id'   => 'require|number',
        'status'    => 'require|in:0,1',
        'old_password' => 'require|length:6,20',
        'new_password' => 'require|length:6,20|different:old_password'
    ];

    protected $message = [
        'username.require'  => '用户名不能为空',
        'username.length'   => '用户名长度必须在4-20个字符之间',
        'password.require'  => '密码不能为空',
        'password.length'   => '密码长度必须在6-20个字符之间',
        'role_id.require'  => '角色不能为空',
        'role_id.number'   => '角色ID必须为数字',
        'status.require'   => '状态不能为空',
        'status.in'        => '状态值不正确',
        'old_password.require' => '原密码不能为空',
        'old_password.length'  => '原密码长度必须在6-20个字符之间',
        'new_password.require' => '新密码不能为空',
        'new_password.length'  => '新密码长度必须在6-20个字符之间',
        'new_password.different' => '新密码不能与原密码相同'
    ];

    // 登录场景
    public function sceneLogin(): AdminValidate
    {
        return $this->only(['username', 'password']);
    }

    // 添加场景
    public function sceneAdd(): AdminValidate
    {
        return $this->only(['username', 'password', 'role_id', 'status']);
    }

    // 修改密码场景
    public function sceneChangePassword(): AdminValidate
    {
        return $this->only(['old_password', 'new_password']);
    }
} 